from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.action_chains import ActionChains # 鼠标事件
import time


serivces = Service("chromedriver.exe")
driver = webdriver.Chrome(service=serivces)
driver.get("https://www.baidu.com")
driver.maximize_window()
driver.implicitly_wait(15)

# 定位到设置
set = driver.find_element(By.ID,"s-usersetting-top")
# 鼠标悬浮在设置按钮上
# ActionChains(driver).move_to_element(set).perform()
set.click()

"""
ActionChains()：放入driver驱动
move_to_element()：放入要移动到的元素
perform()：执行
"""
# 搜索设置
driver.find_elements(By.CLASS_NAME,"set")[0].click()
# 点击保存
driver.find_element(By.CLASS_NAME,"prefpanelgo").click()
time.sleep(2)
# 捕捉弹窗
alert = driver.switch_to.alert
# 点击确定
alert.accept()

# 取消
# alert.dismiss()
time.sleep(5)




